package com.example.everying.framework.websocket.handler;

import com.alibaba.fastjson2.JSONObject;
import com.example.everying.framework.websocket.service.WebSocketChatService;
import com.example.everying.service.chat.ChatConversationService;
import com.example.everying.service.chat.ChatMessagesService;
import com.example.everying.service.system.SysNotificationService;
import jakarta.websocket.Session;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: everying-java
 * @description:
 * @author: szy
 * @create: 2025-09-22 18:20
 **/

@Slf4j
@Component
public class ChatConversationMessageHandler implements MessageHandler {
    private static ChatConversationService chatConversationService;

    @Autowired
    private void setService(ChatConversationService chatConversationService) {
        ChatConversationMessageHandler.chatConversationService = chatConversationService;
    }

    @Override
    public void handle(Session session, JSONObject message) {
        String userId = WebSocketChatService.getUserId(session);
        Long conversationId = message.getLong("conversationId");
        chatConversationService.deleteConversation(userId, conversationId);
        log.info("删除会话：{}", conversationId);
    }
}
